package org.hawk.gwt.ppc.scanner;

import java.net.URL;

import org.hawk.gwt.ppc.utils.Name;

/**
 * General methods for all the source loaders.
 * TODO: Not sure this class really necessary.
 * @author alex.bereznevatiy@gmail.com
 */
abstract class AbstractSourcesLoader implements SourcesLoader {
	AbstractSourcesLoader() {
		super();
	}
	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.scanner.SourcesLoader#getClass(java.lang.String)
	 */
	public URL getClass(String name) {
		if(name==null||name.length()==0){
			return null;
		}
		return getResource(Name.javaToFs(name));
	}
	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.scanner.SourcesLoader#isClassExists(java.lang.String)
	 */
	public boolean isClassExists(String className) {
		return getClass(className)!=null;
	}
	
	protected void validatePackageName(String packageName) {
		if(!Name.isValidPackageName(packageName)){
			throw new IllegalArgumentException(
					"Bad package: "+String.valueOf(packageName));
		}
	}
}